<?php

require_once('../include/GeneralTop.php');
require('../include/class/db.php');

if (!$content_admin) {
	die('<div style="text-align:center">Permission denied...</div>');
}

$db = new db;
if ((isset($_POST["submit"]))) {
    $updateSQL = sprintf("UPDATE petssick SET sickname=%s, sickinfo=%s, pets_class=%s WHERE Id=%s",
                       GetSQLValueString($_POST['sick_name'], "text"),
                       GetSQLValueString($_POST['sick_info'], "text"),
                       GetSQLValueString($_POST['PetSickType'], "int"),
                      
                       GetSQLValueString($_POST['Id'], "int"));

    $db->query($updateSQL);
    header("location:".$_SERVER['PHP_SELF']."?result=suc&Id=".$_POST['Id']);
}

$id = "-1";
if (isset($_GET['Id'])) {
    $id = $_GET['Id'];
}

$sql = sprintf("SELECT * FROM petssick WHERE Id = %s", GetSQLValueString($id, "int"));
$res = $db->query($sql);
$row = $db->fetch($res);

include('AdminPanel.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  <table align="center">
  	<?php
    if($_GET['result'] && 'suc' == $_GET['result']) {
    ?>
    <tr valign="baseline">
      <td colspan="2" nowrap="nowrap" align="center"><font color="green">更新成功...</font></td>
    </tr>
    <?php
    }
    ?>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Id:</td>
      <td><?php echo $row['Id']; ?></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">疾病名:</td>
      <td><input type="text" name="sick_name" value="<?php echo htmlentities($row['sickname'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td height="67" align="right" nowrap="nowrap" valign="top">疾病描述:</td>
      <td><textarea name="sick_info" cols="32" rows="10"><?php echo htmlentities($row['sickinfo'], ENT_COMPAT, 'utf-8'); ?></textarea></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">分类:</td>
      <td>
      	<?php
      	if(1 === (int)$row['pets_class']) {
      		$select1 = 'selected';
      		$select2 = '';
      		$select3 = '';
      	}
      	else if(2 === (int)$row['pets_class']) {
      		$select1 = '';
      		$select2 = 'selected';
      		$select3 = '';
      	}
      	else {
      		$select1 = '';
      		$select2 = '';
      		$select3 = 'selected';
      	}
      	?>
      	<select name="PetSickType" id="PetSickType">
          <option value="1" <?php echo $select1?>>猫狗通病</option>
          <option value="2" <?php echo $select2?>>猫咪健康</option>
          <option value="3" <?php echo $select3?>>狗狗健康</option>
        </select>
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td>
      	<input type="submit" id="submit" name="submit" value="Update record" />&nbsp;&nbsp;
        <input type="button" id="button" onclick="window.location.href='ShowPetSick.php'" value="Back">
      </td>
    </tr>
  </table>
  <input type="hidden" name="Id" value="<?php echo $row['Id']; ?>" />
</form>
<p>&nbsp;</p>
</body>
</html>